import isArray from "lodash/isArray";
import isEmpty from "lodash/isEmpty";
import isObject from "lodash/isObject";

var SUFFIX = 'BASE_REPO';

const routes = [
  {
    path: '/login',
    component: '../layouts/UserLayout',
    routes: [
      {path: '/login', component: './User/Login', title: '登录'},
    ],
  },
  {
    path: '/user',
    component: '../layouts/UserLayout',
    routes: [
      {path: '/user', redirect: '/user/login'},
      {path: '/user/login', component: './User/Login', title: '登录'},
      // {
      //   path: '/user/register', component: './User/Register', routes: [
      //     {
      //       path: '/user/register',
      //       redirect: '/user/register/regScheme',
      //       title: '注册',
      //     },
      //     {
      //       path: '/user/register/regScheme',
      //       component: './User/StepRegForm/Step1',
      //       title: '注册',
      //       // title: '注册 - 选择方案',
      //     }, {
      //       path: '/user/register/regInfo',
      //       component: './User/StepRegForm/Step2',
      //       // title: '注册 - 完善信息',
      //       title: '注册',
      //     }, {
      //       path: '/user/register/regResult',
      //       component: './User/StepRegForm/Step3',
      //       title: '注册完成',
      //     },
      //   ],
      // },
      // {path: '/user/findPassword', component: './User/FindPassword', title: '忘记密码'},
      // {path: '/user/authorLogin', component: './User/AuthorLogin', title: '登录'},
      // {path: '/user/wxAuthor', component: './User/WxAuthorLogin', title: '微信登录'},
    ],
  },
  // {
  //   path: '/transformCode', component: './AuthorBind/TransformCode', title: '绑定微信',
  // },
  {
    path: '/',
    component: '../layouts/BasicLayout',
    routes: [
      {path: '/', redirect: '/view'},
      // {path: '/view/:appCode?/:id?', component: './View', title: ''},
      {path: '/404', component: './Page404', title: '404'},
      {path: '/403', component: './Page403', title: '403'},

      // {
      // path: '/host', component: './Host',
      // routes: [
      //   { path: '/host/', component: './index', title: '站点' },
      //   { path: '/host/detail/:id?', component: './Host/Detail', title: '站点' },
      // ],
      // },
      /////////// 设置
      // {
      //   // routes: [
      //   //   { path: '/userSetting/', component: './UserSetting', title: '个人设置' },
      //   // ],
      // },
      // {
      //   path: '/wxBind', component: './AuthorBind/WxBind', title: '绑定微信',
      // },
    ],
  },
];

let title = SUFFIX;

const recursiveMap = (data, func, parentObj = {}, childKeyName = 'children') => {

  if (isArray(data) && data.length > 0) {

    return data.map((obj, key) => {
      const tmpObj = func(obj, key, parentObj);

      if (isObject(obj)) {

        // @ts-ignore
        if (!isEmpty(obj[childKeyName])) {
          // @ts-ignore
          tmpObj[childKeyName] = recursiveMap(obj[childKeyName], func, tmpObj, childKeyName);
        }
      }
      return tmpObj;
    });

  } else {
    return [];
  }
};
const m = recursiveMap(routes, (route) => {

  if ('undefined' === typeof route.routes || null === route.routes || (route.routes && route.routes.length <= 1)) {
    route.title = `${route.title || ''} - ${title}`;
  } else {
  }
  return route;
}, {}, 'routes');

export default m;
